﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;
using System.Threading;
using System.Xml;

using System.Security;
using System.Security.Cryptography;

namespace Business
{
    public partial class CoreFunction : Form
    {
        public MainForm m_mainform;
        public CoreFunction()
        {
            InitializeComponent();
        }

        
        private string Encryption(string express)//加密
        {
            CspParameters param = new CspParameters();
            param.KeyContainerName = "gzwk2006";
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
            {
                byte[] plaindate = Encoding.Default.GetBytes(express);
                byte[] encryptdate = rsa.Encrypt(plaindate, false);

                return Convert.ToBase64String(encryptdate);
            }
        }
        //
        private string Decrypt(string cip)//解密
        {
            CspParameters param = new CspParameters();
            param.KeyContainerName = "gzwk2006";
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
            {
                byte[] encryptdate = Convert.FromBase64String(cip);
                byte[] decryptdate = rsa.Decrypt(encryptdate, false);
                return Encoding.Default.GetString(decryptdate);
            }
        }
       
        public void getjilu()
        {
            list.Rows.Clear();
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from hexinriji Where shrj_sjsj>'{0}' and shrj_sjsj<'{1}'", dateTimePicker1.Value.ToShortDateString() + " 00:00:00", dateTimePicker2.Value.ToShortDateString() + " 23:59:59");

            sql = sql + " order by shrj_id desc ";
            //保存操作日记
            m_mainform.savecaozuoriji(sql, "查询", "业务系统", "查询核心功能日志审计");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list.Rows.Add();
                    list.Rows[i].Cells[0].Value = string.Format("{0}", i + 1);
                    list.Rows[i].Cells[1].Value = dt.Rows[i]["shrj_yhdh"].ToString().Trim();
                    list.Rows[i].Cells[2].Value = dt.Rows[i]["shrj_yhip"].ToString().Trim();
                    list.Rows[i].Cells[3].Value = dt.Rows[i]["shrj_aqcl"].ToString().Trim();
                    string rjnr = dt.Rows[i]["shrj_rjnr"].ToString().Trim();
                    try
                    {
                        rjnr = Decrypt(dt.Rows[i]["shrj_rjnr"].ToString().Trim());

                    }
                    catch
                    {

                        rjnr = rjnr + "*";
                        list.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
                    }
                    list.Rows[i].Cells[4].Value = rjnr;
                    list.Rows[i].Cells[5].Value = dt.Rows[i]["shrj_sjsj"].ToString().Trim();
                } 
            }
        }

        private void but_query_Click(object sender, EventArgs e)
        {
           
            getjilu();
        }

        private void but_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
    }
}
